<div style="padding:5px"><?
$todaytime = date("YmdHis"); 
if($_SESSION['body']==""){$_SESSION['body']=randomnumber(7);}
$name_c= $_SESSION['body'];
$ip_c=getenv("REMOTE_ADDR");
//kiểm tra mã session này có trong CSDL không
$qrlconnect=mysql_query("select * from tbcounter where counter_name='$name_c' and  counter_ip='$ip_c'");
$n_record=mysql_num_rows($qrlconnect); 
//echo $name_c."<br>";
//Nếu khong có thì sẽ thêm 1 bản ghi mới
if($n_record==0){
	//$qr1=mysql_query("Call sp_tbcounter_them('$ip_c','$name_c','$todaytime')");	
	$qr1=mysql_query("insert into tbcounter (counter_ip,counter_date,counter_name) value ('$ip_c','$todaytime','$name_c');");

	}
else{//$qr1=mysql_query("Call sp_tbcounter_sua('$ip_c','$name_c','$todaytime')");	
$qr1=mysql_query("update tbcounter set  counter_date=  '$todaytime' where  counter_name='$name_c' and counter_ip='$ip_c';");
}

//Đưa ra tổng cố lựot truy cập
	$qr1con=mysql_query("select * from tbcounter");
$n_con=mysql_num_rows($qr1con); 
$solom=$n_con;
echo "Lượt truy cập: <b style=\"color:#FF0000; font-weight:bold;\">".$solom."</b> | ";
//Đưa ra số người đang online
$nexttime = time() - ( 30 * 60);
$onlinetime=date('YmdHis', $nexttime) ;
$qr1conon=mysql_query("select * from tbcounter where counter_date > '$onlinetime'");	
$n_conon=mysql_num_rows($qr1conon); 
$lom=$n_conon;
echo " <b style=\"color:#FF0000; font-weight:bold;\">".$lom."</b> online !";
//echo $todaytime."<br>";
//echo $onlinetime."<br>";
//echo $_SESSION['body'];
?></div>